using System;
using System.Collections.Generic;
using System.Text;
using NBusiness.CodeDom.Services;

namespace NBusiness.CodeDom
{
    [Serializable]
	public abstract class EntityAuthorization : EntityRule
	{
        public EntityAuthorization()
        { }
        public EntityAuthorization(EntityAuthorizationMethod type, string role)
            : this(type, role, true)
        { }
        public EntityAuthorization(EntityAuthorizationMethod type, string role, bool allow)
        {
            _method = type;
            _role = role;
            _allow = allow;
        }

		private bool _allow = true;
		public bool Allow
		{
			get { return _allow; }
			set { _allow = value; }
		}

		private string _role = null;
		public string Role
		{
			get { return _role; }
			set { _role = value; }
		}

		private EntityAuthorizationMethod _method = EntityAuthorizationMethod.Unknown;
		public EntityAuthorizationMethod Method
		{
			get { return _method; }
			set { _method = value; }
		}

		public override string ToString()
		{
			return string.Format("{0} {1} {2}",
				(_allow ? "allow" : "deny"),
				_role,
				_method);
		}
	}
}
